/*
 * @Author: 梁青春
 * @Date: 2025-11-13 15:00:07
 * @LastEditTime: 2025-11-13 15:04:38
 * @LastEditors: 梁青春
 */
// 中文注释：将多级地址数组规范化为后端要求的省市区字段，避免重复代码
export function normalizePatientAddresses(patient) {
  const pick = (arr, keys) => {
    if (Array.isArray(arr) && arr.length >= 3) {
      patient[keys[0]] = arr[0] ?? ''
      patient[keys[1]] = arr[1] ?? ''
      patient[keys[2]] = arr[2] ?? ''
    }
  }
  pick(patient.birthPlace, ['birthProvince', 'birthCity', 'birthDistrict'])
  pick(patient.nativePlace, ['nativeProvince', 'nativeCity', 'nativeDistrict'])
  pick(patient.accountAddress, ['householdProvince', 'householdCity', 'householdDistrict'])
  pick(patient.homeAddress, ['homeProvince', 'homeCity', 'homeDistrict'])
  pick(patient.companyAddress, ['companyProvince', 'companyCity', 'companyDistrict'])
  pick(patient.contactAddress, ['contactProvince', 'contactCity', 'contactDistrict'])
  return patient
}
